package com.talkweb.securitycamera.common.base;

import com.talkweb.securitycamera.common.base.utils.ResourceHelper;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.global.resource.Resource;

/**
 * @version 1.0.1
 * @description:
 * @program: security-camera
 * @Author xiaozhijun
 * @Date 2021/1/25 17:09
 */
public abstract class BaseAbilitySlice extends AbilitySlice {


    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(getLayoutId());
        initData(intent);
        initView(intent);

    }

    /**
     * 获取资源文件中的Resource
     * @param resourceId 资源id
     * @return Resource 资源对象
     */
    public final Resource getResource(int resourceId) {
        return ResourceHelper.getResource(this, resourceId);
    }

    /**
     * 发现组件
     * @param resId 资源id
     * @param <T>   组件类型
     * @return 组件对象
     */
    protected final <T extends Component> T findComponent(int resId) {
        return (T) findComponentById(resId);
    }


    protected abstract int getLayoutId();

    protected void initView(Intent intent) {
    }

    ;

    protected void initData(Intent intent) {
    }

    ;


}
